package com.funo.logic.service;

import cn.hutool.json.JSONUtil;
import com.funo.logic.model.QueryConfig;
import com.funo.logic.response.HandleResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class QueryConfigService extends AbstractService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 根据所属节点id获取查询配置信息
     * @param belongNodeId
     * @return QueryConfig
     * @since 2024年7月25日17:41:52
     */
    public QueryConfig getByBelongNodeId(String belongNodeId) {
        String cacheKey = getCacheKey(belongNodeId);
        String value = stringRedisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return JSONUtil.toBean(value, QueryConfig.class);
    }

    @Override
    public String getCachePrefix() {
        return "queryConfig:";
    }
}
